import { ElMessage } from 'element-plus'

class Download {
  download(url: string) {
    // 无刷新页面下载
    let elemIF: HTMLIFrameElement | null = null
    try {
      elemIF = document.createElement('iframe')
      elemIF.src = url
      elemIF.style.display = 'none'
      const body = document.querySelector('body')
      if (body != null) body.appendChild(elemIF)
    } catch (e) {
      ElMessage.error('下载失败')
    } finally {
      setTimeout(function () {
        if (elemIF != null) {
          elemIF.remove()
        }
      }, 5000)
    }
  }
}
export default Download
